const utils = require('../../../../common/util/util')

Page({
    data: {
        list : []
    },
    onLoad: function (options) {
      let that =this
      that.xInit()
    },
    onShow: function () {
        
    },
    onUnload: function () {
        wx.cloud.callFunction({
            name: 'station_message',
            data: {
                action: "set_to_read"
            }
        }).then(res => {
            wx.hideTabBarRedDot({
              index: 2,
            })
        })
    },

    xInit : function () {
        let that = this
        wx.cloud.callFunction({
            name: 'station_message',
            data: {
              action: "get_station_message"
            }
        }).then(res => {
            let data = res.result
            for(let index in data){
              if(index<=data.length-1){
                if(data[index].is_read==0 && data[Number(index)+1].is_read==1){
                  data[index].show=true
                }else{
                  data[index].show=false
                }
                if(data[index].is_read==0 && data.length==1){
                  data[index].show=true
                }
              }else{
                data[index].show=false
              }
            }
            for(var i in data){
                data[i].create_time = utils.formatTime_chinese(new Date(data[i].create_time))
            }
            that.setData({
                list : data
            })
            // wx.hideLoading()
        })
    },

    xToDetail : function (e) {
        let id = e.currentTarget.dataset.id
        // wx.navigateTo({
        //     url: '/common/pages/posts/detail/index?id=' + id,
        // })
        wx.navigateTo({
          url: '/subtool/pages/community/detail/index?id='+id,
        })
    }

})